﻿<Page 
    x:Class="Cet.IO.DemoModbusNetduino.PageBoardView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:sw="clr-namespace:ToggleSwitch"
    xmlns:local="clr-namespace:Cet.IO.DemoModbusNetduino"
    mc:Ignorable="d" 
    d:DesignHeight="600" d:DesignWidth="1366"
	Title="Board view and interaction"
    >

    
    <Page.Resources>
    
        <DataTemplate x:Key="dtplBoolOutput">
            <local:LedControl
                Value="{Binding Path=Value}"
                Width="24"
                Height="24"
                Margin="1.5"
                />
        </DataTemplate>


        <DataTemplate x:Key="dtplBoolInput">
            <sw:HorizontalToggleSwitch
                IsChecked="{Binding Path=Value, Mode=TwoWay}"
                Margin="1"
                />
        </DataTemplate>


        <DataTemplate x:Key="dtplAnalogOutput">
            <DockPanel
                LastChildFill="True"
                >
                <TextBlock
                    Text="{Binding Path=Value, StringFormat={}{0:P1}}"
                    Style="{StaticResource BasicTextStyle}"
                    Width="60"
                    DockPanel.Dock="Left"
                    />

                <ProgressBar
                    Value="{Binding Path=Value, Mode=TwoWay}"
                    Orientation="Horizontal"
                    Minimum="0.0"
                    Maximum="1.0"
                    Height="24"
                    Margin="0,2"
                    />
            </DockPanel>
        </DataTemplate>


        <DataTemplate x:Key="dtplAnalogInput">
            <DockPanel
                LastChildFill="True"
                >
                <TextBlock
                    Text="{Binding Path=Value, StringFormat={}{0:P1}}"
                    Style="{StaticResource BasicTextStyle}"
                    Width="60"
                    DockPanel.Dock="Left"
                    />

                <Slider
                    Value="{Binding Path=Value, Mode=TwoWay}"
                    Orientation="Horizontal"
                    Minimum="0.0"
                    Maximum="1.0"
                    Height="28"
                    />
            </DockPanel>
        </DataTemplate>

    </Page.Resources>
    
    
    <Grid
        ClipToBounds="True"
        >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="566" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="120" />
        </Grid.RowDefinitions>


        <Canvas
            Grid.Row="0" Grid.Column="1"
            >
            <Image
                Source="/Images/netduino.png"
                Canvas.Left="-3"
                Canvas.Top="-290"
                >
                <Image.LayoutTransform>
                    <TransformGroup>
                        <RotateTransform Angle="90.0" />
                        <ScaleTransform ScaleX="1.5" ScaleY="1.5" />
                    </TransformGroup>
                </Image.LayoutTransform>
            </Image>
        </Canvas>


        <Border
            Grid.Row="0" Grid.Column="1"
            Height="50"
            VerticalAlignment="Top"
            >
            <Border.Background>
                <LinearGradientBrush 
                    StartPoint="0.5,0.0"
                    EndPoint="0.5,1.0"
                    >
                    <GradientStop Color="#FF1D1D1D" Offset="0.2" />
                    <GradientStop Color="#001D1D1D" Offset="1.0" />
                </LinearGradientBrush>
            </Border.Background>
        </Border>

        
        <Grid
            Grid.Row="0" Grid.Column="0"
            Margin="30,10"
            >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            
            <Grid.RowDefinitions>
                <RowDefinition Height="40" />
                <RowDefinition Height="40" />
                <RowDefinition Height="40" />
                <RowDefinition Height="40" />
                <RowDefinition Height="40" />
            </Grid.RowDefinitions>
            
            
            <TextBlock
                Text="Role:"
                Grid.Row="0" Grid.Column="0"
                Style="{StaticResource CaptionTextStyle}"
                />

            <TextBlock
                Text="{Binding Path=Role, Source={x:Static local:HardwareModel.Instance}}"
                Grid.Row="0" Grid.Column="1"
                Style="{StaticResource BasicTextStyle}"
                />

            
            <TextBlock
                Text="Medium:"
                Grid.Row="1" Grid.Column="0"
                Style="{StaticResource CaptionTextStyle}"
                />

            <TextBlock
                Text="{Binding Path=MediumType, Source={x:Static local:HardwareModel.Instance}}"
                Grid.Row="1" Grid.Column="1"
                Style="{StaticResource BasicTextStyle}"
                />


            <TextBlock
                Text="Settings:"
                Grid.Row="2" Grid.Column="0"
                Style="{StaticResource CaptionTextStyle}"
                />

            <TextBlock
                x:Name="PART_Settings"
                Grid.Row="2" Grid.Column="1"
                Style="{StaticResource BasicTextStyle}"
                />


            <TextBlock
                Text="Port:"
                Grid.Row="3" Grid.Column="0"
                Style="{StaticResource CaptionTextStyle}"
                />

            <TextBlock
                x:Name="PART_Port"
                Grid.Row="3" Grid.Column="1"
                Style="{StaticResource BasicTextStyle}"
                />


            <TextBlock
                Text="Address:"
                Grid.Row="4" Grid.Column="0"
                Style="{StaticResource CaptionTextStyle}"
                />

            <TextBlock
                Text="{Binding Path=Address, Source={x:Static local:HardwareModel.Instance}}"
                Grid.Row="4" Grid.Column="1"
                Style="{StaticResource BasicTextStyle}"
                />
        </Grid>
        
        
        <Grid
            Grid.Row="1" Grid.Column="1"
            VerticalAlignment="Center"
            x:Name="CtrPoller"
            >
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            
            <TextBlock
                Text="Polling"
                Style="{StaticResource CaptionTextStyle}"
                Grid.Row="1" Grid.Column="0"
                Margin="8"
                TextAlignment="Center"
                />

            <TextBlock
                Text="Activity"
                Style="{StaticResource CaptionTextStyle}"
                Grid.Row="1" Grid.Column="1"
                Margin="8"
                TextAlignment="Center"
                />

            <sw:HorizontalToggleSwitch
                x:Name="PART_EnablePolling"
                Grid.Row="0" Grid.Column="0"
                />
            
            <local:LedControl
                x:Name="PART_ActLed"
                Width="24"
                Height="24"
                Grid.Row="0" Grid.Column="1"
                Value="{Binding Path=IsPollingEnabled, Source={x:Static local:HardwareModel.Instance}}"
                />
            
        </Grid>
        

        <ItemsControl
            x:Name="IcAnalogs"
            Grid.Row="0" Grid.Column="0"
            Margin="120,0,20,42"
            VerticalAlignment="Bottom"
            >
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <DockPanel
                        LastChildFill="True"
                        >
                        <TextBlock
                            Text="{Binding Path=Value, StringFormat={}{0:P1}}"
                            Style="{StaticResource BasicTextStyle}"
                            Width="60"
                            DockPanel.Dock="Left"
                            />

                        <Slider
                            Value="{Binding Path=Value, Mode=TwoWay}"
                            Orientation="Horizontal"
                            Minimum="0.0"
                            Maximum="1.0"
                            Height="28"
                            />
                    </DockPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>


        <ItemsControl
            x:Name="IcUpper"
            Grid.Row="0" Grid.Column="2"
            Margin="10,24,0,0"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            >
            <!--<ItemsControl.ItemTemplate>
                <DataTemplate>
                    <local:LedControl
                        Value="{Binding Path=Value}"
                        Width="24"
                        Height="24"
                        Margin="1.5"
                        />
                </DataTemplate>
            </ItemsControl.ItemTemplate>-->
        </ItemsControl>


        <ItemsControl
            x:Name="IcLower"
            Grid.Row="0" Grid.Column="2"
            Margin="10,0,0,52"
            HorizontalAlignment="Left"
            VerticalAlignment="Bottom"
            >
            <!--<ItemsControl.ItemTemplate>
                <DataTemplate>
                    <sw:HorizontalToggleSwitch
                        IsChecked="{Binding Path=Value, Mode=TwoWay}"
                        Margin="1"
                        />
                </DataTemplate>
            </ItemsControl.ItemTemplate>-->
        </ItemsControl>

    </Grid>
</Page>
